package cn.lesper.utils;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

//配置属性读取
public class Nature {

    private static final String PROPERTIES_NAME = "db.properties";
    public static String DB_DRIVER = null;
    public static String DB_URL = null;
    public static String DB_USER = null;
    public static String DB_PWD = null;


    static {
        FileInputStream fileInputStream = null;
        try{
            Properties properties = new Properties();
            ClassLoader classloader = Thread.currentThread().getContextClassLoader();
            fileInputStream = new FileInputStream(classloader.getResource(PROPERTIES_NAME).getPath());
            properties.load(fileInputStream);
            DB_DRIVER = properties.getProperty("DB.DRIVER");
            DB_URL = properties.getProperty("DB.URL");
            DB_USER = properties.getProperty("DB.USERNAME");
            DB_PWD = properties.getProperty("DB.PASSWORD");
            System.out.println("============>INFO:读取配置成功");
            showConfig();
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("============>ERR:读取配置失败");
        }finally {
            if (fileInputStream != null){
                try{
                    fileInputStream.close();
                }catch (Exception e){
                    e.printStackTrace();
                    System.out.println("============>ERR:关闭失败");
                }
            }
        }
    }

    private static void showConfig(){
        System.out.println("-----------------------配置信息-----------------");
        System.out.println("dirver: "+DB_DRIVER);
        System.out.println("url: "+DB_URL);
        System.out.println("user: "+DB_USER);
        System.out.println("passworld: "+DB_PWD);
        System.out.println("----------------------------------------------");
    }



}
